import Vue from 'vue'
import VueRouter from 'vue-router'
import AddMajor from '../views/AddMajor.vue'
import About from '../views/About'
import stu_depart from "../components/stu_depart";
import QueryCollege from "../views/QueryCollege";
import AddCollege from "../views/AddCollege";
import  UpdateCollege from "../views/UpdateCollege";
import QueryMajor from "../views/QueryMajor";
import UpdateMajor from "../views/UpdateMajor";
import QueryGrade from "../views/QueryGrade";
import AddGrade from "../views/AddGrade";
import UpdateGrade from "../views/UpdateGrade";
import StudentInfo from "../views/StudentInfo";
import AddStudent from "../views/AddStudent";
import UpdateStudent from "../views/UpdateStudent";
import Statistics from "../views/Statistics";
import Index from "../views/Index";
import HelloWorld from "../components/HelloWorld";

import QueryTCollege from "../views/QueryTCollege";
import QueryTMajor from "../views/QueryTMajor";
import AddTMajor from "../views/AddTMajor";
import AddTCollege from "../views/AddTCollege";
import UpdateTCollege from "../views/UpdateTCollege";
import UpdateTMajor from "../views/UpdateTMajor";
import QueryTeacher from "../views/QueryTeacher";
import AddTeacher from "../views/AddTeacher";
import TeacherInfo from "../views/TeacherInfo";
Vue.use(VueRouter)

const routes = [
   {
      path:'/helloWorld',
      component:HelloWorld
    },
  {
    path: '/about',
    component: About
  },
  {
    path: '/depart',
    component: stu_depart
  },
  {
    path:'/',
    name:"本专科生",
    component:Index,
    show:true,
     redirect:"/depart",
    children:[
      {
        path:'/queryCollege',
        name:"学院",
        component:QueryCollege,
        show:true,
      },
      {
        path:'/addCollege',
        name:"添加学院",
        component:AddCollege,
        show:false
      },
      {
        path:'/updateCollege',
        component:UpdateCollege,
        show:false
      },
      {
        path: '/queryMajor',
        name: "专业",
        component: QueryMajor,
        show: true
      },
      {
        path:'/addMajor',
        name:"添加专业",
        component:AddMajor,
        show:false
      },
      {
        path:'/updateMajor',
        component:UpdateMajor,
        show:false
      },
      {
        path: '/queryGrade',
        name: "年级",
        component: QueryGrade,
        show: true
      },
      {
        path:'/addGrade',
        name:"添加年级",
        component:AddGrade,
        show:false
      },
      {
        path:'/updateGrade',
        component:UpdateGrade,
        show:false
      },
      {
        path:'/StudentInfo',
        name: '学生信息',
        component:StudentInfo,
        show:true,
        meta:{
          auth:true
        }
      },
      {
        path:'/updateStudent',
        component:UpdateStudent,
        show:false
      },
      {
        path:'/addStudent',
        component:AddStudent,
        show:false
      },

      ]
   },
  {
    path:'/',
    name:"教职工",
    component:Index,
    show:true,
    children: [
      {
        path: '/QueryTCollege',
        name: '部门',
        component: QueryTCollege,
        show: true
      },
      {
        path: '/QueryTMajor',
        name: '子部门',
        component: QueryTMajor,
        show: true
      },
      {
        path: '/QueryTeacher',
        name: '教职工信息',
        component: QueryTeacher,
        show: true
      },
      {
        path:'/addTMajor',
        name:"添加子部门",
        component:AddTMajor,
        show:false
      },
      {
        path:'/addTCollege',
        name:"添加部门",
        component:AddTCollege,
        show:false
      },
      {
        path: '/UpdateTCollege',
        name: "更新部门",
        component: UpdateTCollege,
        show:false
      },
      {
        path: '/UpdateTMajor',
        name: "更新专业",
        component: UpdateTMajor,
        show:false
      },
      {
        path: '/AddTeacher',
        name: "添加教职工",
        component: AddTeacher,
        show: false
      },
      {
        path: '/TeacherInfo',
        name: "教师详情",
        component: TeacherInfo,
        show: true
      }
    ]
  },
  {
    path:'/statistics',
    name:"统计关注",
    component:Index,
    show:true,
    children:[
      {
        path:'/statistics',
        name:"学生关注",
        component:Statistics,
        show:true
      }
    ]
  },



]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  if(to.meta.auth){
    if(localStorage.getItem('root')){
      next()

    }else {
      next({path: 'depart'})
      alert('请先登录')

    }
  }
  else {
    next()
  }
})

export default router
